package com.purchase.ml.resource;

import com.purchase.ml.annotations.OperLog;
import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.entity.log.ExceptionLog;
import com.purchase.ml.mapper.log.ExceptionLogMapper;
import com.purchase.ml.service.prod.DealerProductService;
import com.purchase.ml.utils.MD5;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by kyyang on 2021/1/8 10:03
 */
@ApiIgnore
@RestController
@RequestMapping("/test")
@Slf4j
public class TestResource {


    @Autowired
    private ExceptionLogMapper exceptionLogMapper;
    @Autowired
    private DealerProductService productService;

    @RequestMapping("/dealerProduct")
    public ApiRestResult save(){
        productService.changeMasterDealerStock(999L);
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.GET,path = "/list")
    @OperLog(operDesc = "xx模块查询",operModul = "xx模块",operType = "查询")
    public ApiRestResult list(){
        return ApiRestResult.ok();
    }


    @RequestMapping(method = RequestMethod.GET,path = "/list2")
    @OperLog(operDesc = "xxxx描述",operModul = "xxxx模块",operType = "查询")
    public ApiRestResult test(){
        int i = 10/0;
        return ApiRestResult.ok();
    }

    @RequestMapping(method = RequestMethod.GET,path = "/list3")
    @OperLog(operDesc = "xxxx描述",operModul = "xxxx模块",operType = "查询")
    public ApiRestResult test3(){
        ExceptionLog exceptionLog = exceptionLogMapper.selectById(1);
        return ApiRestResult.ok(exceptionLog);
    }


    @RequestMapping(method = RequestMethod.POST,path = "/redirect")
    public void redirect(HttpServletResponse response) throws Exception{
        response.sendRedirect("https://www.baidu.com/s?wd=123456");
        //重定向到URL; 账户主动跳转；
//     response.sendRedirect("http://www.baidu.com");
//        response.sendRedirect("http://192.168.0.166:8080?oid=123456");
//     return  new ModelAndView(new RedirectView("http://www.baidu.com"));
    }



    public static void main(String[] args) {
        // String s = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        //System.out.println(s);
        String b3cbad3766814ecca06fd1403cd8902c = MD5.md5("123456", "b3cbad3766814ecca06fd1403cd8902c");
        System.out.println(b3cbad3766814ecca06fd1403cd8902c);
    }
}
